package pers.qianyu.month_202103.date_20210307.contest_231;

import org.junit.*;

/**
 * 5697. 检查二进制字符串字段
 * https://leetcode-cn.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/
 *
 * @author mizzle rain
 * @date 2021-03-07 10:33
 */
public class CheckOnesSegment {
    public boolean checkOnesSegment(String s) {
        int n = s.length();
        char[] arr = s.toCharArray();
        int i = 0;
        while (i < n && arr[i] == '1') {
            i++;
        }
        while (i < n && arr[i] == '0') {
            i++;
        }
        return i == n;
    }

    @Test
    public void test1() {
        boolean r = new CheckOnesSegment().checkOnesSegment("1001");
        Assert.assertFalse(r);
    }

    @Test
    public void test2() {
        boolean r = new CheckOnesSegment().checkOnesSegment("110");
        Assert.assertTrue(r);
    }

    @Test
    public void test3() {
        boolean r = new CheckOnesSegment().checkOnesSegment("1");
        Assert.assertTrue(r);
    }
}
